/* mrpd.t   Matrials Requirement Planning DELETE TRIGGER                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.1 $                                                           */
/*V8:ConvertMode=NoConvert                                                    */
/* $Revision: 1.1 $       BY: Julie Milligan       DATE: 07/23/02   ECO: *P0BZ*  */
/******************************************************************************/

TRIGGER PROCEDURE FOR DELETE OF mrp_det.

{mfdeclre.i }
define new shared work-table wf_old_mrp_det like mrp_det.

/* Remove any Material Requirements Planning Pegging Detail associated with   */
/* The current mrp_det record.                                                */
for each mrpp_det where mrpp_supply_mrp_keyid = mrp_keyid exclusive-lock:
   delete mrpp_det.
end.
for each mrpp_det where mrpp_demand_mrp_keyid = mrp_keyid exclusive-lock:
   delete mrpp_det.
end.

HK:
do:
    if not can-find ( first dt_mstr where dt_table = "mrp_det" and dt_type = "DEL" ) then leave HK.
    
    if not can-find ( first wf_old_mrp_det ) then do:
        create wf_old_mrp_det.
        if recid(wf_old_mrp_det)= -1 then .
    end.
    
    buffer-copy mrp_det to wf_old_mrp_det no-error.
    
    if mrp_det.mrp_dataset <> "sod_det" then return.

    for first dt_mstr no-lock where dt_table = "mrp_det" and dt_type = "DEL" :
    
    	run CreateDthist(input dt_table, input dt_field, input dt_type, input "", input "", 
            input recid(mrp_det), input mrp_det.mrp_dataset, input mrp_det.mrp_part, input mrp_det.mrp_nbr, input mrp_det.mrp_line,
            input mrp_det.mrp_line2, input "", input "", input "").
        	
    end.
end.

{hkdttrans.i}
